package com.ailk.evaluation.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.anhorn.webshare.base.dao.BaseJdbcDao;
import com.anhorn.webshare.base.util.Page;


public class UserDao extends BaseJdbcDao{
	
	
	public Map findUser(String username, String company) {
		String sql = "select * from users where user_code = ? ";
		List<Map> rs = this.getJdbcTemplate().queryForList(sql, new Object[]{username+"/"+company});
		return rs.get(0);
	}
	public Page queryUser(String role,int current ,int limit) {	
		
		String	sql = "select * from USERS where role="+role+" order by id desc";
		
		return this.getPage(sql, current, limit);
	}
	
	public void insertUser(String eamil,String password){
		String sql = "insert into user (email,password,update_time) values(?,?)";
		this.getJdbcTemplate().update(sql,new Object[]{
				eamil,password,new Date()
		});
	}
	public void updateUser(String password,String email){
		this
		.getJdbcTemplate()
		.update("update user set password =?  where email = ?",
				new Object[]{
				password,
				email
		});		
	}
	public Map findUserByName_Pass(String email,String password){
		List tempList = this.getJdbcTemplate().queryForList(
				"select * from USERS where email=? and password=?",
				new Object[] { email, password });
		if (tempList.size() != 0){
			Map user =(Map)tempList.get(0);
			return user;
		}
		else
			return null;	
	}

}
